<?php
$row	=	array();
if(isset($_GET['id']) && intval($_GET['id']) != 0){
	$q	=	mysql_query("SELECT * FROM sach WHERE id=".intval($_GET['id']));
	$row	=	mysql_fetch_array($q);
	mysql_query("UPDATE sach SET luot_xem=".intval($row['luot_xem']+1)." WHERE id=".intval($_GET['id']));
	
	if($_SERVER['REQUEST_METHOD'] == 'POST')
	{
		$item['id']		=	$row['id'];
		$item['price']	=	$row['gia_bia'];
		$item['num']	=	1;
		if(isset($_SESSION['carts'])){
			$carts	=	$_SESSION['carts'];
			$exist = false;
			foreach($carts as $k => $v){
				if($v['id'] == $row['id']){
					$_SESSION['carts'][$k]['num'] =	$_SESSION['carts'][$k]['num']+1;
					$exist = true;
					break;
				}
			}
			if($exist == false){
				$_SESSION['carts'][] = $item;
			}
		}
		else{
			$_SESSION['carts'][]=$item;
		}
	}
}


?>
<div id="detail">
	<div class="head">
		<a>
			<img src="<?php echo $CONFIG['site_url'].$row['anh'];?>" width="93" height="120" onerror="this.src='<?php echo $CONFIG['site_url'].'images/onerror_72.jpg'?>'" />
		</a>
		
		<table class="left">
			<tr>
				<td><b>Tên sách:</b></td>
				<td><?php echo $row['ten_sach']?></td>
			</tr>
			<tr>
				<td><b>Tác giả:</b></td>
				<td><?php echo $row['tac_gia']?></td>
			</tr>
			<tr>
				<td><b>Nhà xuất bản:</b></td>
				<td><?php echo $row['nha_xb']?></td>
			</tr>
			<tr>
				<td><b>Giá bìa:</b></td>
				<td><?php echo $row['gia_bia']?></td>
			</tr>
			<tr>
				<td><b>Số trang:</b></td>
				<td><?php echo $row['so_trang']?></td>
			</tr>
			<tr>
				<td><b>Trọng lượng:</b></td>
				<td><?php echo $row['trong_luong']?></td>
			</tr>
		</table>
		
		<table class="right">
			<tr>
				<td>Lượt xem:&nbsp;<?php echo $row['luot_xem'];?></td>
			</tr>
			<tr>
				<td>
				<form action="" method="post">
					<input type="submit" value="Thêm vào giỏ hàng"/>
				</form>
				</td>
			</tr>
		</table>
	</div>
</div>

<h2>Sách liên quan</h2>
<ul>
<?php
	$q1	=	mysql_query("SELECT * FROM sach WHERE id <> ".$row['id']." AND ma_danh_muc=".intval($row['ma_danh_muc'])." ORDER BY ngay_tao DESC LIMIT 10");
	while($r	=	mysql_fetch_array($q1)):
?>
	<li><a href="index.php?act=view_doc&id=<?php echo $r['id'];?>"><?php echo $r['ten_sach'];?></a></li>
<?php endwhile;?>
</ul>
